/**
 * 抖音关注：程序员三丙
 * 知识星球：https://t.zsxq.com/j9b21
 */
package sanbing.example.dylike.infrastructure.queue.kafka;

import jakarta.annotation.PostConstruct;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import sanbing.example.dylike.util.PropertyUtils;

import java.util.Map;

@Component
@ConditionalOnProperty(prefix = "queue", value = "type", havingValue = "kafka")
@Profile("!test")
public class KafkaTopicConfigs {
    public static final String NUM_PARTITIONS_SETTING = "partitions";

    @Value("${queue.kafka.topic-properties.core:}")
    private String coreProperties;
    @Value("${queue.kafka.topic-properties.rpc:}")
    private String rpcProperties;

    @Getter
    private Map<String, String> coreConfigs;
    @Getter
    private Map<String, String> rpcRequestConfigs;
    @Getter
    private Map<String, String> rpcResponseConfigs;

    @PostConstruct
    private void init() {
        this.coreConfigs = PropertyUtils.getProps(coreProperties);
        this.rpcRequestConfigs = PropertyUtils.getProps(rpcProperties);
        this.rpcResponseConfigs = PropertyUtils.getProps(rpcProperties);
        this.rpcResponseConfigs.put(NUM_PARTITIONS_SETTING, "1");
    }

}
